package com.weiku.task;

import java.io.File;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.List;
import org.quartz.Job;
import org.quartz.JobDataMap;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.weiku.until.FileUntil;

public class WaybillTask implements Job{
	final Logger log = LoggerFactory.getLogger(WaybillTask.class);
	
	public void execute(JobExecutionContext jobExecutionContext) throws JobExecutionException {
		JobDataMap jobDetailDataMap = jobExecutionContext.getJobDetail().getJobDataMap();
		String src=jobDetailDataMap.getString("localhost_yundan");
        String desc=jobDetailDataMap.getString("haiguan_yundan");
		Date date = new Date();
        SimpleDateFormat sf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        System.err.println("运单回执查询开始时间是："+ sf.format(date));
        long start=System.currentTimeMillis();
        try { 
	       //1.把海关的XML回执放到固定的路径下
			//检查海关路径下的XML
			List<String> srcpath=FileUntil.traverseFolder(desc);
			File f=new File(src);
			if(!f.exists()){
				System.out.println("创建目录");
				f.mkdirs();
				log.info("创建目录:"+src);
			}
			System.out.println("目标文件路径是："+srcpath);
			for(String path:srcpath){
				FileUntil.copyWaybillXmlFile(path,src);
				log.info("文件复制成功      源文件路径："+path);
			}
        } catch (Exception e) {
			e.printStackTrace();
			log.error("错误信息："+e.getMessage());
		}
        long end=System.currentTimeMillis();
        long time=end-start;
        System.err.println("运单回执查询结束时间是："+ sf.format(date)+"/n 耗时:"+time+"毫秒");
    }
}
